import Proy1

contarLa :: String -> Integer
contarLa [] = 0
contarLa [x] = 0
contarLa (x:y:ys)	|(x=='l' && y=='a') = 1 + contarLa ys
			|otherwise = contarLa (y:ys)
			
intercal :: a -> [a] -> [[a]]
intercal n [] = [[n]]
intercal n (x:xs) = (n:x:xs) : encabs x (intercal n xs)

intercalm :: a -> [a] -> [[a]]
intercalm n [] = [[n]]
intercalm n (x : xs) = (n:x:xs) : map (x :) (intercalm n xs)

sacaelMin :: (Bounded a, Ord a) => [a] -> [a]
sacaelMin [] = []
sacaelMin (x:xs) |x == minList (x:xs) = xs
		 |otherwise = x : sacaelMin xs

selectionSort :: (Bounded a, Ord a) => [a] -> [a]
selectionSort [] = []
selectionSort (x:xs)	|x==(minList (x:xs)) = x:selectionSort xs
			|otherwise = minList xs : selectionSort (x:sacaelMin xs) 
			
conjuntos :: [a] -> [[a]]
conjuntos [] = [[]]
conjuntos (x:xs) = encabs x (conjuntos xs) ++ conjuntos xs

rayuelas :: Integer -> [[Int]]
rayuelas 1 = [[]]
rayuelas 2 = [[1]]
rayuelas n = encabs 2 (rayuelas (n-2)) ++ encabs 1 (rayuelas (n-1))

sacar :: Int -> [Int]
sacar 1 = [0]
sacar 2 = [1,0]
sacar (n+2) = sacar n ++ [1] ++ poner n ++ sacar (n+1)


poner :: Int -> [Int]
poner 1 = [0]
poner 2 = [0,1]
poner (n+2) = poner (n+1) ++ sacar n ++ [1] ++ poner n

posCambio :: Integral a => [a] -> a -> [[a]]
posCambio [] 0 = [[]]
posCambio [] (v+1) = []
posCambio (x:xs) v	|v < 0 = []
			|otherwise = encabs x (posCambio (x:xs) (v-x)) ++ posCambio xs v
			
cambio :: Integral a => [a] -> a -> [a]
cambio xs v = head (posCambio xs v)






